class MyIterator(object):
    """ iterator is a object that implements the iterator protocol
    it is based on two methods:
    next() , which returns the next item of the container
    __iter__(), which returns the iterator itself
    """
    def __init__(self,step):
        self.step = step

    def next(self):
        if self.step == 0 :
            raise StopIteration
        self. step -= 1
        return self.step

    def __iter__(self):
        return self

for e in MyIterator(4):
    print e
